package com.vanvalt.core.utils;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thinkgem.jeesite.common.persistence.CrudDao;
import com.thinkgem.jeesite.common.persistence.DataEntity;
import com.thinkgem.jeesite.common.utils.IdGen;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

/**
 * @author Xiaoyang
 *
 */
public final class SvrUtils {

	private static final Logger log = LoggerFactory.getLogger(SvrUtils.class);
	
	private SvrUtils(){};
	
	public static void save(DataEntity entity,CrudDao dao)  {
		log.debug("保存记录！");
		
		User user = UserUtils.getUser();
		
		if(null == entity.getId() || "".equals(entity.getId())){
			log.debug("插入操作！");
			
			entity.setId(IdGen.uuid());
			entity.setCreateDate(new Date());
			entity.setCreateBy(user);
			entity.setUpdateDate(new Date());
			entity.setUpdateBy(user);
			dao.insert(entity);
			
		} else {
			log.debug("更新操作");
			
			entity.setUpdateDate(new Date());
			entity.setUpdateBy(user);
			dao.update(entity);
		}
		
		log.info("保存记录成功！");
	}
}
